using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Reverse : MonoBehaviour
{
    public RenderTexture sourceRenderTexture;
    private RawImage rawImage;
    private Material flipMaterial;

    void Start()
    {
        rawImage = GetComponent<RawImage>();
        sourceRenderTexture = rawImage.texture as RenderTexture;

        // Create a material with the flip shader
        Shader flipShader = Shader.Find("Custom/FlipShader");
        flipMaterial = new Material(flipShader);

        // Assign the render texture to the material
        flipMaterial.mainTexture = sourceRenderTexture;

        // Create a temporary texture to store the flipped image
        Texture2D flippedTexture = new Texture2D(sourceRenderTexture.width, sourceRenderTexture.height, TextureFormat.RGBA32, false);

        // Render the flipped image to the temporary texture
        RenderTexture.active = sourceRenderTexture;
        flippedTexture.ReadPixels(new Rect(0, 0, sourceRenderTexture.width, sourceRenderTexture.height), 0, 0);
        flippedTexture.Apply();
        RenderTexture.active = null;

        // Assign the flipped texture to the raw image
        rawImage.texture = flippedTexture;
    }
}